#pragma once
#include "connection_handler.h"
#include "http.h"

#include <vector>
#include <string>


class TStaticFileHandler : public TConnectionHandler {
public:
    TStaticFileHandler(TConnectionManager& connections)
    : TConnectionHandler(connections)
    , BasePath("")
    , IoBuffer(0, '\0')
    {}
    //request header larger than ioBufferSize will be rejected
    bool Init( const std::string& path
             , unsigned int ioBufferSize );
    void Handle(int connectionId);
private:
    bool FileTransfer(int connectionId, int file);
    bool WriteHeader( char* buffer
                    , unsigned int bufferSize
                    , int status
                    , unsigned int fileSize
                    , int connectionId );
    bool ReadHeader(char* buffer, unsigned int size, int connectionId, unsigned int& headerSize);
    THttpRequest ParseHeader(const char* buffer, unsigned int size);

    typedef std::vector<char>   TBuffer;
    std::string BasePath;
    TBuffer     IoBuffer;
};
